package com.luoying.itew.util;

import com.luoying.itew.common.AntaiApplication;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by octopus on 17/6/20.
 */

public class UserUtils {
    private static String access_tokem = null;
    private static String android_id = null;

    private static String username = null;
    private static String userpassword = null;


    public static String getAccess_tokem() {
        return access_tokem;
    }

    public static void setAccess_tokem(String access_tokem) {
        UserUtils.access_tokem = access_tokem;
    }

    public static String getAndroid_id() {
        return AntaiApplication.android_id;
    }

    public static void setAndroid_id(String android_id) {
        UserUtils.android_id = android_id;
    }

    private static int userCityId = 0;
    private static String userCityName = null;
    //warnlevel = gray（例）
    private static List warnLevel = new ArrayList();
    //private static String fullname = null;
    //districtname=广东省深圳市罗湖区（例）
    private static List districtname = new ArrayList();

    private static List bdLat = new ArrayList();
    private static List bdLng = new ArrayList();
    private static List monitorPointName = new ArrayList();
    private static List monitorStatusDesc = new ArrayList();
    /**@deprecated */
    private static List checkInterval = new ArrayList();
    private static List location = new ArrayList();
    /**@deprecated */
    private static List monitorTemperature  = new ArrayList();
    /**@deprecated */
    private static List monitorHumidity  = new ArrayList();
    private static List monitorPointId = new ArrayList();
    private static List warnCoefficient = new ArrayList();
    private static List<String> monitorTypes = new ArrayList<>();
    private static List<Integer> weakOutDipPlanes = new ArrayList<>();
    private static List<String> materiaTypes = new ArrayList<>();
    private static List<Integer> monitorHeights = new ArrayList<>();
    private static List<String> receiverTypes = new ArrayList<>();
    private static List<String> antennaVendors = new ArrayList<>();
    private static List<String> antennaTypes = new ArrayList<>();

    public static int getDistrictNum(){
        return districtname.size();
    }
    public static String getWarnlevel(int i){
        return warnLevel.get(i).toString();
    }
    public static String getDistrict(int i){
        return districtname.get(i).toString();
    }


    public static void setArea(JSONObject jsonObject) throws JSONException {

        JSONObject resultEntity = jsonObject.getJSONObject("resultEntity");
        JSONObject userCity = resultEntity.getJSONObject("userCity");

        userCityId = userCity.getInt("areaId");
        userCityName = userCity.getString("areaName");

        JSONArray jsonArray1 = resultEntity.getJSONArray("districtJson");
        warnLevel.clear();
        districtname.clear();
        for(int i=0;i<jsonArray1.length();i++) {
            JSONObject user1 = null;
            user1 = (JSONObject) jsonArray1.get(i);
            warnLevel.add(user1.getString("warnLevel"));
            districtname.add((user1.getJSONObject("district")).getString("districtName"));
            setDistrict(user1);
        }
    }

    public static String getUserCityName() {
        return userCityName;
    }

    public static void setDistrict(JSONObject jsonObject) throws JSONException{
        JSONArray jsonArray = jsonObject.getJSONArray("monitorPoints");

        bdLat.clear();
        bdLng.clear();
        monitorPointId.clear();
        monitorPointName.clear();
        monitorStatusDesc.clear();
        warnCoefficient.clear();
        location.clear();
        monitorTypes.clear();
        weakOutDipPlanes.clear();
        materiaTypes.clear();
        monitorHeights.clear();
        receiverTypes.clear();
        antennaVendors.clear();
        antennaTypes.clear();

        for(int i=0;i<jsonArray.length();i++) {
            JSONObject user = null;
            user = (JSONObject) jsonArray.get(i);
            bdLat.add(user.getString("bdLat"));
            bdLng.add(user.getString("bdLng"));
            monitorPointId.add(user.getInt("monitorPointId"));
            monitorPointName.add(user.getString("monitorPointName"));
            monitorStatusDesc.add(user.getString("monitorStatusDesc"));
            checkInterval.add(user.getInt("checkInterval"));
            warnCoefficient.add(user.getDouble("warnCoefficient"));
            monitorTypes.add(user.getString("monitorTypeLabel"));
            weakOutDipPlanes.add(user.getInt("weakOutDipPlane"));
            materiaTypes.add(user.getString("materialTypeDesc"));
            monitorHeights.add(user.getInt("monitorHeight"));
            receiverTypes.add(user.getString("monitorReceiverType"));
            antennaVendors.add(user.getString("monitorAntennaVendor"));
            antennaTypes.add(user.getString("monitorAntennaType"));
            if(user.has("monitorTemperature")){
                monitorTemperature .add(user.getString("monitorTemperature"));
            }else{
                monitorTemperature .add("暂无数据");
            }
            if (user.has("monitorHumidity")){
                monitorHumidity .add(user.getString("monitorHumidity"));
            }else {
                monitorHumidity .add("暂无数据");
            }
            location.add((user.getJSONObject("monitorArea")).getString("fullName"));
            if (user.has("monitorArea")) {
                location.add((user.getJSONObject("monitorArea")).getString("fullName"));
            }
            else {
                location.add("未知区域");
            }
        }
    }

    public static String getMonitorTypes(int i) {
        return monitorTypes.get(i);
    }
    public static int getWeakOutDipPlane(int i) {
        return weakOutDipPlanes.get(i);
    }

    public static String getReceiverType(int i) {
        return receiverTypes.get(i);
    }

    public static String getAntennaVendors(int i) {
        return antennaVendors.get(i);
    }

    public static String getAntennaType(int i) {
        return antennaTypes.get(i);
    }

    public static int getMonitorHeight(int i) {
        return monitorHeights.get(i);
    }

    public static String getMaterialType(int i) {
        return materiaTypes.get(i);
    }




    public static Double getbdLat(int i){
        return Double.valueOf(String.valueOf(bdLat.get(i)));
    }
    public static Double getbdLng(int i){
        return Double.valueOf(String.valueOf(bdLng.get(i)));
    }
    public static String getMoniName(int i){
        return (String) monitorPointName.get(i);
    }
    public static int getMonitorPointId(int i) {
        return (Integer) monitorPointId.get(i);
    }
    public static String getMonitorStatusDesc(int i){
        return (String) monitorStatusDesc.get(i);
    }
    public static String getLocation(int i){
        return (String) location.get(i);
    }
    public static int getChecklevel(int i){
        return (int) checkInterval.get(i);
    }
    public static String getTem(int i){
        return (String) monitorTemperature.get(i);
    }
    public static String getHum(int i){
        return (String) monitorHumidity.get(i);
    }
    public static int getId(int i){
        return (Integer) monitorPointId.get(i);
    }
    public static double getWarnConficent(int i){
        return (Double) warnCoefficient.get(i);
    }
    public static int getNum(){
        return bdLat.size();
    }

    public static int findIndex(int monitorPointId){
        for (int i = 0;i<UserUtils.getNum();i++){
            if (monitorPointId == UserUtils.getId(i)){
                return i;
            }
        }
        return -1;
    }

    //当前选择的见监测点ID
    private static int monitorId = 0;

    public static int getMonitorId() {
        return monitorId;
    }

    public static void setMonitorId(int i) {
        //UserUtils.monitorId = UserUtils.getId(i);
        monitorId = i;
    }

    public static String getUsername() {
        return username;
    }

    public static void setUsername(String username) {
        UserUtils.username = username;
    }

    public static String getUserpassword() {
        return userpassword;
    }

    public static void setUserpassword(String userpassword) {
        UserUtils.userpassword = userpassword;
    }

    /**@deprecated */
    private static String warnData = null;

    /**@deprecated */
    public static String getWarnData() {
        return warnData;
    }

    /**@deprecated */
    public static void setWarnData(String warnData) {
        UserUtils.warnData = warnData;
    }
}
